#!/bin/bash

#=======================================================================
# git-logdiff
# File ID: b51c5d58-5406-11e0-a9ae-552d51fb27db
# Compare two different Git histories. Syntax:
# git logdiff <commit1> <commit2> [rootcommit]
# License: GNU General Public License version 2 or later.
#=======================================================================

test "$1" = "-p" && { p_str=-p; shift; }
ext=.git-logdiff.$(date +%s).$$.tmp
c1=$(git log -1 --format=format:%h $1)
c2=$(git log -1 --format=format:%h $2)
if test -n "$3"; then
    mbase="$3"
else
    mbase="$(git merge-base $c1 $c2)"
fi
c1=$mbase..$c1
c2=$mbase..$c2
git log --raw --format=raw $p_str $c1 >/tmp/$c1$ext
git log --raw --format=raw $p_str $c2 >/tmp/$c2$ext
vimdiff /tmp/{$c1,$c2}$ext
rm /tmp/{$c1,$c2}$ext
